//客户筛选管理CreateInfo.js  网格下的内容控件 ProjectSource.js

var ProjectSourceDemo = function(){
	
	var userSelector = null;
	var selectUserId = [];
	
	// 立项信息元素-----begin

	var projectCode = new Ext.form.TextField({
		fieldLabel : '客户编号',
		width : 150,
		disabled:true
	});
	
	var projectName = new Ext.form.TextField({
		fieldLabel : '客户名称',
		width : 300,
		allowBlank : false
	});
	//取得所属区域下拉列表里的值
	this.getGridArea = new Ext.data.JsonStore({
		url : '../project/getGridArea.form?timesnap=' + new Date().getTime(),
		method : 'POST',
		root : 'result',
		fields : ['AREA_ID','NAME']
	});
	
	this.getGridAreaMap = function(){
		var items = this.getGridArea.data.items;
		var v = null;
		var values = [];
		for(var i=0;i<items.length;i++){
			v = items[i].data;
			values[v.AREA_ID] = v.NAME;
		}
		return values;
	};
	
	var projectArea = new Ext.form.ComboBox( {
		fieldLabel : '所属区域',
		//hiddenName : 'type',
		store :this.getGridArea ,
		mode : 'local',
		displayField : 'NAME',
		triggerAction : 'all',
		editable : false,
		valueField : 'AREA_ID',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true,
		allowBlank : false
	});
	this.renderprojectType = function(value){
		return OMS.PROJECTTYPEOBJECT[value];
	};
	var projectType = new Ext.form.ComboBox( {
		fieldLabel : '客户类型',
		//hiddenName : 'type',
		store : OMS.PROJECTTYPE,
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true,
		allowBlank : false
	});
	
	var projectMoney = new Ext.form.NumberField({
		fieldLabel : '估算金额',
		width : 150
	});
	
//	var projectCreateDate = new Ext.form.DateField( {
//		fieldLabel : '客户立项时间',
//		format : 'Y-m-d',
//		width : 150
//	});
	
	var projectComplateDate = new Ext.form.DateField( {
		fieldLabel : '预计签约时间',
		format : 'Y-m-d',
		width : 150
	});
	
	var projectJoinHeader = new Ext.form.TextField({
		fieldLabel : '参与领导',
		width : 150,
		listeners: {
			   'render': function(cmp) {
					var self = cmp.ownerCt.ownerCt;
					//console.info(self);
					cmp.getEl().on('click', function(){showUser1();}, self); 
				}
			}
	});
	
	var projectCustName = new Ext.form.TextField({
		fieldLabel : '公司地址',
		width : 300,
		allowBlank : false
	});
	
	var projectEmpNum = new Ext.form.NumberField({
		fieldLabel : '员工人数',
		width : 150
	});
	
	var connName = new Ext.form.TextField({
		fieldLabel : '联系人姓名',
		width : 120,
		allowBlank : false
	});
	
	var connOffTel = new Ext.form.TextField({
		fieldLabel : '办公电话',
		width : 120,
		allowBlank : false
	});
	
	var connCellPhone = new Ext.form.TextField({
		fieldLabel : '手机',
		width : 120
	});
	
	var connEmail = new Ext.form.TextField({
		fieldLabel : 'EMAIL',
		width : 120,
		vtype : 'email'
	});
	// 立项信息元素-----end
	
	this.projectInfo = new Ext.form.FieldSet({
		title : '基础信息',
		collapsible : true,
		autoHeight : true,
		width : 930,
		items : [{layout:'column',
				  defaults:{layout:'form'},
				  items:[{columnWidth:0.5,items:[projectCode]},
				 	//	 {columnWidth:0.5,items:[TestText]},
				         {columnWidth:0.5,items:[projectName]}]},
				  {layout:'column',
				   defaults:{layout:'form',columnWidth:0.3},
				   items:[{items:[projectArea,projectJoinHeader]},
						  {items:[projectType,projectComplateDate]},
						  {items:[projectMoney]}]},
				   {xtype:'fieldset',title:'联系信息',collapsible:true,autoHeight:true,
					items:[{layout:'column',
						   defaults:{layout:'form'},
						   items:[{columnWidth:0.5,items:[projectCustName]},
							      {columnWidth:0.5,items:[projectEmpNum]}
						   ]},
						  {layout:'column',
						   defaults:{layout:'form'},
						   items:[{columnWidth:0.25,items:[connName]},
								  {columnWidth:0.25,items:[connOffTel]},
								  {columnWidth:0.25,items:[connCellPhone]},
								  {columnWidth:0.25,items:[connEmail]}
								 ]
						  }]}
				]
	});
	
	// 需求信息元素----begin
//	var projectNeedName = new Ext.form.TextField({
//		fieldLabel : '项目目标',
//		width : 800
//	});
	
	var projectCustNeedItems = new Ext.form.CheckboxGroup({
	    xtype: 'checkboxgroup',
	    fieldLabel: '客户需求',
	    itemCls: 'x-check-group-alt',
	    columns: 4,
	    width : 500,
	    items: [
	        {boxLabel: '基础配套建设', name: 'cust4-1',value:'1'},
	        {boxLabel: '通信配套建设', name: 'cust4-2',value:'2'},
	        {boxLabel: '专线', name: 'cust4-3',value:'3'},
	        {boxLabel: '语音类', name: 'cust4-4',value:'4'}
	    ]
	});
	
	var projectOther = new Ext.form.TextField({
		fieldLabel : '其他',
		width : 120
	});
	
	var projectNeedServer = new Ext.form.TextArea({
		fieldLabel : '服务要求',
		width : 800
	});
	
	var projectNeedFunction = new Ext.form.TextArea({
		fieldLabel : '实现功能',
		width : 800
	});
	
	var projectNeedBus = new Ext.form.TextArea({
		fieldLabel : '业务提供',
		width : 800
	});
	
	var projectNeedSummary = new Ext.form.TextArea({
		fieldLabel : '备注',
		width : 800
	});
	
	// 需求信息元素----end
	
	this.projectNeed = new Ext.form.FieldSet({
		title : '需求信息',
		collapsible : true,
		autoHeight : true,
		width : 930,
		items : [
		         {layout:'column',
				  defaults:{layout:'form'},
				  items:[{columnWidth:0.75,items:[projectCustNeedItems]},
				         {columnWidth:0.25,items:[projectOther]}]
				  },projectNeedServer,projectNeedFunction,projectNeedBus,projectNeedSummary
		        ]
	});
	
	this.projectIsVs = new Ext.form.Checkbox({
		boxLabel: '是否有竞争对手',
		scope : this,
	    listeners : {
			scope : this,
			check : function(thiz,checked){
				if(checked)
					this.projectVsInfo.show();
				else
					this.projectVsInfo.hide();
			}
		}
	});
	
	// 竞争对手信息---begin
	var projectVsName = new Ext.form.TextField({
		fieldLabel : '竞争对手名称',
		width : 200
	});
	
	var projectVsAssigner = new Ext.form.TextField({
		fieldLabel : '项目负责人',
		width : 150
	});
	
	var projectVsDate = new Ext.form.DateField( {
		fieldLabel : '介入时间',
		format : 'Y-m-d',
		width : 150
	});
	
	var projectVsGood = new Ext.form.TextArea({
		fieldLabel : '优势',
		width : 250
	});
	
	var projectVsBad = new Ext.form.TextArea({
		fieldLabel : '劣势',
		width : 250
	});
	// 竞争对手信息---end
	
	this.projectVsInfo = new Ext.form.FieldSet({
		title : '竞争对手信息',
		collapsible : true,
		autoHeight : true,
		width : 930,
		items : [{layout:'column',
				  defaults:{layout:'form'},
				  items:[{columnWidth:0.4,items:[projectVsName]},
				  		 {columnWidth:0.3,items:[projectVsAssigner]},
				  		 {columnWidth:0.3,items:[projectVsDate]}
				  		]},
				 {layout:'column',
				  defaults:{layout:'form'},
				  items:[{columnWidth:0.5,items:[projectVsGood]},
						 {columnWidth:0.5,items:[projectVsBad]}
						]}]
	});
	
	this.projectVsInfo.hide();
	//为控件设置值
	this.setCompValue = function(data){
		//console.info(projectCustNeedItems);
		projectCode.setValue(data.PROJECT_ID);
		projectName.setValue(data.PROJECT_NAME);
		projectArea.setValue(data.AREA_ID);
		projectType.setValue(data.PROJECT_TYPE);
		projectMoney.setValue(data.EST_AMT);
		projectCreateDate.setValue(data.PROJECT_CREATE_DT);
		projectComplateDate.setValue(data.EST_DT);
		projectJoinHeader.setValue(data.JOIN_LEADER);
		projectCustName.setValue(data.CUSTOMER_NAME);
		projectEmpNum.setValue(data.STAFF_NUM);
		connName.setValue(data.CONTACT_PERSON);
		connOffTel.setValue(data.OFF_TEL);
		connCellPhone.setValue(data.MOBILE);
		connEmail.setValue(data.EMIAL);
		
		projectNeedName.setValue(data.PROJECT_TARGET);
		var array=new Array();
		array=data.CUST_REQ.split(',');
		if(array.length>0){
			projectCustNeedItems.items.items[0].setValue(false);
			projectCustNeedItems.items.items[1].setValue(false);
			projectCustNeedItems.items.items[2].setValue(false);
			projectCustNeedItems.items.items[3].setValue(false);
			projectOther.setValue("");
			for(i=0;i<array.length;i++){
				var cus_req=array[i];
				if(cus_req!=null&cus_req != 'null'){
					if(cus_req == 1){
						projectCustNeedItems.items.items[0].setValue(true);
					}else
					if(cus_req == 2){
						projectCustNeedItems.items.items[1].setValue(true);
					}else
					if(cus_req == 3){
						projectCustNeedItems.items.items[2].setValue(true);
					}else
					if(cus_req == 4){
						projectCustNeedItems.items.items[3].setValue(true);
					}else{
						projectOther.setValue(data.CUST_REQ);
					}
				}
			}
		}
		projectNeedServer.setValue(data.SERVICE_REQ);
		projectNeedFunction.setValue(data.IMP_FUNC);
		projectNeedBus.setValue(data.OWNER_PROVIDE);
		projectNeedSummary.setValue(data.REMARK);
		
		//projectIsVs:projectIsVs.setValue(data.);
		projectVsName.setValue(data.COMPETITOR);
		projectVsAssigner.setValue(data.PROJECT_OWNER);
		projectVsDate.setValue(data.INVOLVE_DT);
		projectVsGood.setValue(data.ADVANTAGE);
		projectVsBad.setValue(data.DISADVANTAGE);
	};
	//为控件设置值
	this.setCompValueAndDisabled = function(data){
		projectCode.setValue(data.PROJECT_ID);
		projectName.setValue(data.PROJECT_NAME);
		projectArea.setValue(data.AREA_ID);
		projectType.setValue(data.PROJECT_TYPE);
		projectMoney.setValue(data.EST_AMT);
		projectCreateDate.setValue(data.PROJECT_CREATE_DT);
		projectComplateDate.setValue(data.EST_DT);
		projectJoinHeader.setValue(data.JOIN_LEADER);
		projectCustName.setValue(data.CUSTOMER_NAME);
		projectEmpNum.setValue(data.STAFF_NUM);
		connName.setValue(data.CONTACT_PERSON);
		connOffTel.setValue(data.OFF_TEL);
		connCellPhone.setValue(data.MOBILE);
		connEmail.setValue(data.EMIAL);
		projectCode.disable();
		projectName.disable();
		projectArea.disable();	
		projectType.disable();	
		projectMoney.disable();	
		projectCreateDate.disable();	
		projectComplateDate.disable();	
		projectJoinHeader.disable();	
		projectCustName.disable();
		projectEmpNum.disable();	
		connName.disable();	
		connOffTel.disable();	
		connCellPhone.disable();	
		connEmail.disable();	
		
		projectNeedName.setValue(data.PROJECT_TARGET);
		projectOther.setValue(data.CUST_REQ);
		projectNeedServer.setValue(data.SERVICE_REQ);
		projectNeedFunction.setValue(data.IMP_FUNC);
		projectNeedBus.setValue(data.OWNER_PROVIDE);
		projectNeedSummary.setValue(data.REMARK);
		projectNeedName.disable();	
		projectOther.disable();	
		projectNeedServer.disable();	
		projectNeedFunction.disable();	
		projectNeedBus.disable();	
		projectNeedSummary.disable();
		
		projectVsName.setValue(data.COMPETITOR);
		projectVsAssigner.setValue(data.PROJECT_OWNER);
		projectVsDate.setValue(data.INVOLVE_DT);
		projectVsGood.setValue(data.ADVANTAGE);
		projectVsBad.setValue(data.DISADVANTAGE);
		projectVsName.disable();	
		projectVsAssigner.disable();	
		projectVsDate.disable();	
		projectVsGood.disable();	
		projectVsBad.disable();
		var array=new Array();
		array=data.CUST_REQ.split(',');
		if(array.length>0){
			projectCustNeedItems.items.items[0].setValue(false);
			projectCustNeedItems.items.items[1].setValue(false);
			projectCustNeedItems.items.items[2].setValue(false);
			projectCustNeedItems.items.items[3].setValue(false);
			projectOther.setValue("");
			for(i=0;i<array.length;i++){
				var cus_req=array[i];
				if(cus_req!=null&cus_req != 'null'){
					if(cus_req == 1){
						projectCustNeedItems.items.items[0].setValue(true);
					}else
					if(cus_req == 2){
						projectCustNeedItems.items.items[1].setValue(true);
					}else
					if(cus_req == 3){
						projectCustNeedItems.items.items[2].setValue(true);
					}else
					if(cus_req == 4){
						projectCustNeedItems.items.items[3].setValue(true);
					}else{
						projectOther.setValue(data.CUST_REQ);
					}
				}
			}
		}
		projectCustNeedItems.disable();
	};
	//取得控件里的值
	this.getProjectId= function(){
		value = projectCode.getValue();
		return value;
	};
	
	//保存立项信息
	
	this.getCompValue = function(status){
		return {
			project_id:projectCode.getValue(),
			projectName:projectName.getValue(),
			projectArea:projectArea.getValue(),
			projectType:projectType.getValue(),
			projectMoney:projectMoney.getValue(),
			projectCreateDate:projectCreateDate.getValue()?projectCreateDate.getValue().format('Y-m-d'):'',
			projectComplateDate:projectComplateDate.getValue()?projectComplateDate.getValue().format('Y-m-d'):'',
			projectJoinHeader:projectJoinHeader.getValue(),
			projectCustName:projectCustName.getValue(),
			projectEmpNum:projectEmpNum.getValue(),
			connName:connName.getValue(),
			connOffTel:connOffTel.getValue(),
			connCellPhone:connCellPhone.getValue(),
			connEmail:connEmail.getValue(),
			
			projectNeedName:projectNeedName.getValue(),
			projectCustNeedItems:getCus_req(),
			projectOther:projectOther.getValue(),
			projectNeedServer:projectNeedServer.getValue(),
			projectNeedFunction:projectNeedFunction.getValue(),
			projectNeedBus:projectNeedBus.getValue(),
			projectNeedSummary:projectNeedSummary.getValue(),
			
			//projectIsVs:projectIsVs.getValue(),
			projectVsName:projectVsName.getValue(),
			projectVsAssigner:projectVsAssigner.getValue(),
			projectVsDate:projectVsDate.getValue()?projectVsDate.getValue().format('Y-m-d'):'',
			projectVsGood:projectVsGood.getValue(),
			projectVsBad:projectVsBad.getValue(),
			projectStatus:status
		};
	};
	var getCus_req = function(){
		var iptvalue1 = null;
		var iptvalue2 = null;
		var iptvalue3 = null;
		var iptvalue4 = null;
		var iptvalue = null;
		if(projectCustNeedItems.items.items[0].checked){
			iptvalue1=1;
		}
		if(projectCustNeedItems.items.items[1].checked){
			iptvalue2=2;
		}
		if(projectCustNeedItems.items.items[2].checked){
			iptvalue3=3;
		}
		if(projectCustNeedItems.items.items[3].checked){
			iptvalue4=4;
		}	
		iptvalue = iptvalue1+','+iptvalue2+','+iptvalue3+','+iptvalue4;
		if(iptvalue == 'null,null,null,null'){
			return null;
		}else{
			return iptvalue;
		}
	};
	var showUser1 = function(){
		//var scope=this;
		selectUserId = [129,3840,20151]; 
		if(userSelector==null){
			userSelector=new Tree.User(selectUserId,function(o){
				//scope.setUsers1(o);
				setUsers1(o);
			},null,'105');
		}
		userSelector.show();
	};

	var setUsers1 = function(o){
		//alert(Ext.util.JSON.encode(o));
		var names = [];
		selectUserId =[];
		for(var i=0;i<o.length;i++) {
			names.push(o[i].text);
			selectUserId.push(o[i].id);
		}
		projectJoinHeader.setValue(names.join(';'));
	};
};